﻿using System.Collections.Generic;
using System.ComponentModel;
using EDMDesigner.Business.Util;

namespace EDMDesigner.Business.SSDL.EntityType
{
    public class EntityType : INotifyPropertyChanged, INamedElement
    {
        public SSDLContainer Container { get; internal set; }

        public StoreType? StoreType { get; set; }
        public string Schema { get; set; }
        public string StoreName { get; set; }
        public string StoreSchema { get; set; }
        public string Table { get; set; }

        public string _name;
        public string Name
        {
            get { return _name; }
            set 
            {
                _name = value;
                OnPropertyChanged("Name");
            }
        }

        private string _entitySetName;
        public string EntitySetName
        {
            get { return _entitySetName; }
            set
            { 
                _entitySetName = value;
                OnPropertyChanged("EntitySetName");
            }
        }

        private string _definingQuery;
        public string DefiningQuery
        {
            get { return _definingQuery; }
            set 
            {
                _definingQuery = value;
                OnPropertyChanged("DefiningQuery");
            }
        }

        private List<Property.Property> _properties;
        public List<Property.Property> Properties
        {
            get
            {
                if (_properties == null)
                    _properties = new List<Property.Property>();
                return _properties;
            }
        }

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        public override string ToString()
        {
            return Name;
        }
    }
}
